{include file="public/header" /}

<!--<div class="wrapper wrapper-content">-->
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">

                <div class="ibox-content">
                    <form method="get" class="form-horizontal" id="form1">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">{:lang('role name')}</label>
                            <div class="col-sm-9">
                                <input name="roleName" type="text" class="form-control"
                                       value="{$roleInfo.roleName}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">{:lang('permission manage')}</label>
                            <div class="col-sm-9">
                                <table class="table table-striped">
                                    <thead>
                                    <tr>
                                        <!--<th>-->
                                            <!--<input type="checkbox">-->
                                        <!--</th>-->
                                        <th>{:lang('permission name')}</th>
                                        <th>{:lang('add')}</th>
                                        <th>{:lang('edit')}</th>
                                        <th>{:lang('delete')}</th>
                                        <th>{:lang('view')}</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {volist name="allAuth" id="v" key="k"}
                                    <tr>
                                        <!--<td></td>-->
                                        <td>
                                            {$v.authName}
                                        </td>
                                        {volist name="v.sons" id="v2" key="k2"}
                                        <td>
                                            {if condition="in_array($v2['id'],$roleInfo['authIDs'])"}
                                            <input type="checkbox" name="authIDs[]" value="{$v2.id}" checked>
                                            {else/}
                                            <input type="checkbox" name="authIDs[]" value="{$v2.id}">
                                            {/if}
                                        </td>
                                        {/volist}
                                    </tr>
                                    {/volist}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <input type="hidden" name="roleID" value="{$roleInfo.id}">

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary" type="button" onclick="doSubmit()">{:lang('edit')}</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
<!--</div>-->

{include file="public/footer" /}
<script>
    function doSubmit() {
        $.ajax({
            url: "{:U('Admin/editRole')}",
            type: 'post',
            data: $('#form1').serialize(),
            dataType: 'JSON',
            success: function (data) {
                if (data.status == 1) {
                    layer.msg(data.msg);
                    setTimeout(function () {
                        // location.reload();
                        parent.location.reload();
                    }, 1000)
                } else {
                    layer.msg(data.msg);
                }
            }
        });
        return false;
    }
</script>
